/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.acq.web.areainfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.acq.entity.areainfo.AcqAreaInfo;
import com.thinkgem.jeesite.modules.acq.service.areainfo.AcqAreaInfoService;

/**
 * 产地环境信息Controller
 * @author lj
 * @version 2018-04-08
 */
@Controller
@RequestMapping(value = "${adminPath}/acq/areainfo/acqAreaInfo")
public class AcqAreaInfoController extends BaseController {

	@Autowired
	private AcqAreaInfoService acqAreaInfoService;
	
	@ModelAttribute
	public AcqAreaInfo get(@RequestParam(required=false) String id) {
		AcqAreaInfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = acqAreaInfoService.get(id);
		}
		if (entity == null){
			entity = new AcqAreaInfo();
		}
		return entity;
	}
	
	@RequiresPermissions("acq:areainfo:acqAreaInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(AcqAreaInfo acqAreaInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<AcqAreaInfo> page = acqAreaInfoService.findPage(new Page<AcqAreaInfo>(request, response), acqAreaInfo); 
		model.addAttribute("page", page);
		return "modules/acq/areainfo/acqAreaInfoList";
	}

	@RequiresPermissions("acq:areainfo:acqAreaInfo:view")
	@RequestMapping(value = "form")
	public String form(AcqAreaInfo acqAreaInfo, Model model) {
		model.addAttribute("acqAreaInfo", acqAreaInfo);
		return "modules/acq/areainfo/acqAreaInfoForm";
	}

	@RequiresPermissions("acq:areainfo:acqAreaInfo:edit")
	@RequestMapping(value = "save")
	public String save(AcqAreaInfo acqAreaInfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, acqAreaInfo)){
			return form(acqAreaInfo, model);
		}
		acqAreaInfoService.save(acqAreaInfo);
		addMessage(redirectAttributes, "保存产地环境信息成功");
		return "redirect:"+Global.getAdminPath()+"/acq/areainfo/acqAreaInfo/?repage";
	}
	
	@RequiresPermissions("acq:areainfo:acqAreaInfo:edit")
	@RequestMapping(value = "delete")
	public String delete(AcqAreaInfo acqAreaInfo, RedirectAttributes redirectAttributes) {
		acqAreaInfoService.delete(acqAreaInfo);
		addMessage(redirectAttributes, "删除产地环境信息成功");
		return "redirect:"+Global.getAdminPath()+"/acq/areainfo/acqAreaInfo/?repage";
	}

}